import js from '@eslint/js';
import reactPlugin from 'eslint-plugin-react';

export default [
  // 基础 JavaScript 推荐规则
  js.configs.recommended,

  // React 专属规则
  {
    files: ['**/*.{js,jsx}'],
    languageOptions: {
      ecmaVersion: 2021,
      sourceType: 'module',
      globals: {
        es2021: true,
        browser: true,
        node: true,
      },
      parserOptions: {
        ecmaFeatures: {
          jsx: true, // 启用 JSX
        },
      },
    },
    settings: {
      react: {
        version: 'detect', // 自动检测 React 版本
      },
    },
    plugins: {
      react: reactPlugin,
    },
    rules: {
      ...reactPlugin.configs.recommended.rules,

      // 可选：自定义规则
      'no-console': ['warn'],
      'no-debugger': ['error'],
      'prefer-const': ['error'],
      'react/prop-types': 'off', // 如果你使用 TypeScript，可以关闭 propTypes
      'react/react-in-jsx-scope': 'off', // React 17+ 不需要引入 React
      'react/no-unescaped-entities': 'off',
    },
  },
];
